<!-- 排班管理 -->
<template>
  <div class="dashboard-container transport-task customer-list-box">
    <!-- 搜索区域 -->
    <div class="search-container">
      <div class="item">
        <div class="search-label">员工账号：</div>
        <el-input
          v-model="params.employeeNumber"
          clearable
          placeholder="请输入员工账号"
          class="search-main"
        />
      </div>
      <div class="item">
        <div class="search-label">员工姓名：</div>
        <el-input
          v-model="params.name"
          clearable
          placeholder="请输入员工姓名"
          class="search-main"
        />
      </div>
      <div class="item">
        <div class="search-label">工作模式:</div>
        <el-select
          v-model="params.agencyId"
          placeholder="请选择工作模式"
        >
          <el-option
            v-for="item in workList"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </div>
      <div class="item">
        <div class="search-label">月份:</div>
        <el-date-picker
          v-model="params.month"
          type="date"
          placeholder="选择日期"
          format="MM 月 dd 日"
          value-format="MM-dd"
        >
        </el-date-picker>
      </div>
      <div class="item">
        <div class="search-label">所属机构</div>
        <el-input
          clearable
          placeholder="请输入所属机构"
          class="search-main"
        />
      </div>
      <div class="item">
        <el-button
          type="warning"
          @click="doSearch"
        >搜索</el-button>
        <el-button>重置</el-button>
      </div>
    </div>
    <div class="work-btns">
      <el-button
        type="warning"
        @click="$router.push('/transit/workArrange-setting')"
      >排班设置</el-button>
      <el-button
        class="bind-btn"
        @click="dialogVisible = true"
      >绑定排班</el-button>
    </div>
    <div
      class="content"
      style="margin-left: 45px"
    >
      <el-table
        :data="list"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        >
        </el-table-column>

        <el-table-column
          prop="employeeNumber"
          label="员工账号"
          width="150px"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="员工姓名"
          width="150px"
        >
        </el-table-column>
        <el-table-column
          prop="phone"
          label="员工电话"
          width="150px"
        >
        </el-table-column>
        <el-table-column
          prop="userType"
          label="员工角色"
          width="150px"
        >
        </el-table-column>
        <el-table-column
          prop="workPatternName"
          label="当前工作状态"
          width="150px"
        >
        </el-table-column>
        <el-table-column
          v-for="(item, index) in 31"
          :key="index"
          :label="`${index + 1}`"
        >
          <template #default="scope">
            <div
              v-if="scope.row.workSchedules[index]"
              class="work"
            >上</div>
            <div
              v-else
              class="rest"
            >休</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页器 -->
    <div class="page-container">
      <el-pagination
        style="text-align: center;"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="+counts"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
    <!-- 绑定排版弹框 -->
    <el-dialog
      title="人工调整"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <div class="content">
        <el-radio
          v-model="radio"
          label="1"
        >礼拜制</el-radio>
        <el-radio
          v-model="radio"
          label="2"
        >连续制</el-radio>
        <div class="sele">
          <div style="width: 90px">工作模式</div>
          <el-select v-model="workTypeId">
            <el-option
              v-for="item in workTypeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
      </div>

      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="warning"
          @click="submitPb"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { workManage, selectWorkHistoryList, peopleSet } from '@/api/transit'
export default {
  data() {
    // 列表数据
    return {
      workTypeList: [],
      workTypeId: null,
      radio: null,
      dialogVisible: false, // 弹框开关
      params: {
        agencyId: '', // 网点
        employeeNumber: null, // 员工账号
        month: '', // 月份
        name: '', // 员工姓名
        page: 1, // 页数
        pageSize: 10 // 每页条数
      },
      counts: null,
      list: [], // 列表数据
      workList: [], // 工作模式下拉
      userIdList: [] // 被选中的id列表
    }
  },
  watch: {
    async radio(newValue) {
      const res = await selectWorkHistoryList()
      if (newValue === '1') {
        // 礼拜制
        this.workTypeList = res.data[1].filter(item => item.workPatternType === 1)
      } else if (newValue === '2') {
        // 连续制
        this.workTypeList = res.data[1].filter(item => item.workPatternType === 2)
      }
    }
  },
  created() {
    this.getWorkList()
  },
  methods: {
    // 搜索
    doSearch() {
      this.getList()
    },
    // 分页器
    handleCurrentChange(num) {
      this.params.page = num
      this.getList()
    },
    // 被选中
    handleSelectionChange(val) {
      this.userIdList = val.map(item => {
        return item.id
      })
    },
    // 获取分页数据
    async getList() {
      const res = await workManage(this.params)
      this.list = res.data.items
      this.counts = res.data.counts
    },
    // 获取工作模式下拉
    async getWorkList() {
      const res = await selectWorkHistoryList()
      this.workList = res.data[1]
    },
    // 排班
    async submitPb() {
      await peopleSet({
        userIdList: this.userIdList,
        workTypeId: this.workTypeId,
        userType: '1',
        workPatternType: '1'
      })
      this.$message.success('排班成功')
      this.dialogVisible = false
      this.getList()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.search-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 30px;
  background-color: #fff;

  .item {
    display: flex;
    align-items: center;
    margin-top: 20px;
    margin-left: 30px;
    width: 560px;

    .search-label {
      width: 100px;
    }

    .el-select {
      width: 450px;
    }

    .search-main {
      width: 450px;
      margin-right: 10px;
    }
  }
}

.work-btns {
  padding-left: 60px;
  height: 80px;
  background-color: #fff;

  .bind-btn {
    color: #e15536;
    background-color: #fff3ef;
    border: 1px solid #e15536;
  }
}

::v-deep th.date {
  .cell {
    padding-left: 17px !important;
  }
}

.work {
  width: 24px;
  height: 24px;
  background: #ffeeeb;
  border: 1px solid #e15536;
  border-radius: 50%;
  text-align: center;
  color: #e15536;
  font-size: 13px;
}

.history-name {
  width: auto !important;

  ::v-deep .el-input__inner {
    width: 293px;
  }
}

.workArrange-manage-people-setting {
  ::v-deep .el-dialog__body {
    padding: 30px 50px 10px 50px !important;
  }

  ::v-deep .el-dialog__footer {
    padding-bottom: 40px;
  }
}

.work-type {
  ::v-deep .el-form-item__content {
    margin-left: 40px !important;
  }

  ::v-deep .el-radio:first-child {
    margin-right: 80px !important;
  }

  ::v-deep.el-radio__label {
    font-weight: bold;
    color: #333333;
  }
}

.dialog-footer {
  .el-button {
    width: 89px;
    height: 36px;
    padding: 10px 20px;
  }
}

.rest {
  width: 24px;
  height: 24px;
  background: #eff3f8;
  border: 1px solid #d8dde3;
  border-radius: 50%;
  text-align: center;
  color: #20232a;
  font-size: 13px;
}

.alert {
  margin: 10px 0px;
}

.pagination {
  margin-top: 40px;
}

.transport-task ::v-deep .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}

// 下拉框
::v-deep .el-select {
  width: 100%;
}

/*定义滚动条轨道 内阴影+圆角*/
::v-deep .el-table--scrollable-x .el-table__body-wrapper {
  padding-bottom: 5px;
  margin-bottom: 5px;

  &::-webkit-scrollbar {
    height: 10px;
  }

  /*定义滑块 内阴影+圆角*/
  &::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: rgba(144, 147, 153, 0.3);
  }

  &::-webkit-scrollbar-track-piece {
    margin-right: 3px;
    margin-left: 3px;
  }
}

::v-deep .el-card {
  overflow: initial;
}
.content {
  text-align: center;
  .sele {
    align-items: center;
    margin-top: 10px;
    display: flex;
  }
}
</style>

<style></style>
